package team.seekers.oj.third.controller;

import net.gjerull.etherpad.client.EPLiteClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author hbc
 * @Date 2022/2/13
 */
@RestController
@RequestMapping("/etherpad")
public class EtherpadController {

    String etherpadAddress = "http://www.1.116.143.234:9001";
    String apiKey = "1505f60378012e9801a6c49ff7be3f7f4ac4feb603a96f5feac11ae04e99ab9e";

    /**
     * 创建一个代码协同白板
     */
    @GetMapping("/create/{padId}")
    public Void create(@PathVariable String padId) {
        EPLiteClient client = new EPLiteClient(etherpadAddress,apiKey);
        client.createPad(padId);
        return null;
    }


    /**
     * 获取协同白板中的代码
     */
    @GetMapping("/content/{padId}")
    public  String content(@PathVariable String padId) {
        EPLiteClient client = new EPLiteClient(etherpadAddress,apiKey);
        return client.getText(padId).get("text").toString();
    }
}

